<script setup>
import { reactive, getCurrentInstance } from 'vue'
import { useAllDataStore } from '@/stores'
import { useRouter } from 'vue-router'

const { proxy } = getCurrentInstance()
const store = useAllDataStore()
const router = useRouter()

const loginForm = reactive({
  username: '',
  password: ''
})

const handleLogin = async () => {
  const res = await proxy.$api.getMenu(loginForm)
  // console.log(res)
  // 拿到菜单以后，在哪显示
  store.updateMenuList(res.menuList)
  store.state.token = res.token
  store.addMenu(router)
  router.push('/home')
}
</script>

<template>
  <div class="body-login">
    <el-form :model="loginForm" class="login-container">
      <h1>欢迎登录</h1>
      <el-form-item>
        <el-input type="input" placeholder="请输入用户名" v-model="loginForm.username" clearable />
      </el-form-item>
      <el-form-item>
        <el-input type="password" placeholder="请输入密码" v-model="loginForm.password" show-password />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin" style="width: 100%;">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<style lang="less" scoped>
.body-login {
  position: relative;
  width: 100%;
  height: 100vh;
  background-image: url(@/assets/images/background.png);
  background-size: 100% 100%;
  overflow: hidden;

  .login-container{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    // margin: 250px auto;
    padding: 35px 35px 15px 35px;
    width: 400px;
    background-color: #fff;
    border: 1px solid #eaeaea;
    border-radius: 15px;
    box-shadow: 0 0 25px #cacaca;

    h1 {
      margin-bottom: 20px;
      text-align: center;
      color: #505450;
    }

    :deep(.el-form-item__content) {
      justify-content: center;
    }
  }
}
</style>